import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { getClient } from '/@/api/sys/test';
import { Alert,Tag } from 'ant-design-vue';
import { Button } from '/@/components/Button';
import { router } from '/@/router';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '单据编号',
      width: 150,
      dataIndex: 'BillId',
      sorter: true,
      sortOrder: 'ascend',
      customRender: ({ record }) => {
        function NavToDetail(){
          router.push({name:'test2',query:{BillId:record.BillId}})
          
        }
        return (
          <Button type="link" size="small" onClick={NavToDetail}>
            {() => record.BillId}
          </Button>
        );
      },
    },
    {
      title: '客户',
      dataIndex: 'CompanyName',
      width: 120,
    },
    {
      title: '业务员',
      dataIndex: 'HrName',
    },
    {
      title: '状态',
      dataIndex: 'BillState',
      width: 80,
      customRender:({ text, index }: { text: any; index: number })=>{
        if(text==='Audited'){
          return <Tag color="green">已审核</Tag>
        }else{
          return <Tag color="blue">未审核</Tag>
        }
      }
    },
  ];
}
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      // ...getAdvanceSchema(5),
      {
        field: `SortColumn`,
        label: `当前页`,
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        defaultValue:'WorkDate',
        show:false
      },
      {
        field: `BillId`,
        label: `单据编号`,
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `time`,
        label: `时间段`,
        component: 'RangePicker',
        colProps: {
          xl: 12,
          xxl: 8,
        }
      },
      {
        field: 'ClientId',
        component: 'ApiSelect',
        label: '供应商',
        required: true,
        componentProps: {
          // more details see /src/components/Form/src/components/ApiSelect.vue
          api: getClient,
          resultField: 'list',
          // use name as label
          labelField: 'CompanyName',
          // use id as value
          valueField: 'ClientNum',
          // not request untill to select
          immediate: false,
          onChange: (e) => {
            console.log('selected:', e);
          },
          // atfer request callback
          onOptionsChange: (options) => {
            console.log('get options', options.length, options);
          },
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      
    ],
  };
}
export function getBasicData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
    return arr;
  })();
  return data;
}

export function getTreeTableData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
        children: [
          {
            id: `l2-${index}`,
            name: 'John Brown',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
        ],
      });
    }
    return arr;
  })();

  return data;
}

